const Mock = require('mockjs')
let tableData = []
Mock.mock('http://localhost:8443/querRole', 'get')
Mock.mock('http://localhost:8443/addRoles', 'post', (params) => { // 新增数据模拟接口
  console.log(params.body)
  let addObj = JSON.parse(params.body)
  tableData.push(addObj)
  return {
    code: 200,
    message: 'success'
  }
})
Mock.mock('http://localhost:8443/updateRoles', 'post', (params) => { // 修改数据模拟接口
  console.log(params.body)
  let editObj = JSON.parse(params.body)
  tableData.forEach(item => {
    if (item.role_id === editObj.role_id) {
      item.role_name = editObj.role_name
      item.role_level = editObj.role_level
      item.role_info = editObj.role_info
    }
  })
  return {
    code: 200,
    message: 'success'
  }
})
Mock.mock('http://localhost:8443/deleteRoles', 'post', (params) => { // 删除数据模拟接口
  console.log(params.body)
  let deleteObj = JSON.parse(params.body)
  let deleteId = deleteObj.role_id
  tableData = tableData.filter(val => val.role_id !== deleteId)
  return {
    code: 200,
    message: 'success'
  }
})
Mock.mock('http://localhost:8443/queryMenus', 'get', require('./json/queryMenus.json'))
Mock.mock('http://localhost:8443/userMenus', 'get', require('./json/userMenus.json'))
Mock.mock('http://localhost:8443/Menus', 'get', require('./json/queryMeunByRole.json'))
Mock.mock('http://localhost:8443/DictMenus', 'get', require('./json/queryDict.json'))

Mock.mock('http://localhost:8443/deleteMenus', 'post', (params) => { // 删除数据模拟接口
  console.log(params.body)
  let deleteObj = JSON.parse(params.body)
  let deleteId = deleteObj.id
  tableData = tableData.filter(val => val.id !== deleteId)
  return {
    code: 200,
    message: 'success'
  }
})
// Mock.mock('http://localhost:8443/updateMenu', 'post', (params) => {
//   console.log(params.body)
//   // let updateObj = JSON.parse(params.body)
//   return {
//     code: 200,
//     message: 'success'
//   }
// })

Mock.mock('http://localhost:8443/addMenus', 'post', (params) => { // 新增数据模拟接口
  console.log(params.body)
  let addObj = JSON.parse(params.body)
  tableData.push(addObj)
  return {
    code: 200,
    message: 'success'
  }
})
Mock.mock('http://localhost:8443/updateMenus', 'post', (params) => { // 修改数据模拟接口
  console.log(params.body)
  let editObj = JSON.parse(params.body)
  tableData.forEach(item => {
    if (item.icon === editObj.icon) {
      item.d = editObj.d
      item.e = editObj.e
      item.f = editObj.f
      item.name = editObj.name
      item.address = editObj.address
      item.module_name = editObj.module_name
      item.a = editObj.a
      item.catalog = editObj.catalog
    }
  })
  return {
    code: 200,
    message: 'success'
  }
})
Mock.mock('http://localhost:8443/addDict', 'post', (params)=>{
  let addObj = JSON.parse(params.body)
  console.log(params.body)
})
Mock.mock('http://localhost:8443/updateDict', 'post', (params)=>{
  let editObj = JSON.parse(params.body)
  console.log(params.body)
})
Mock.mock('http://localhost:8443/deleteDict', 'post', (params) => { // 删除数据模拟接口
  console.log(params.body)
  let deleteObj = JSON.parse(params.body)
  let deleteId = deleteObj.dictionary_id
  tableData = tableData.filter(val => val.dictionary_id !== deleteId)
  return {
    code: 200,
    message: 'success'
  }
})
